package org.duang.kit;

import java.io.File;

import org.duang.config.Config;



public class PathKit {
	
	private static String webRootPath; 
	
	private static String basePackagePath;
	
	private static String libPath;
	
	
	public static String getWebRootPath() {
		if (webRootPath == null)
			webRootPath = detectWebRootPath();
		return webRootPath;
	}
	
	private static String detectWebRootPath() {
		try {
			String path = PathKit.class.getResource("/").toURI().getPath();
			return new File(path).getParentFile().getParentFile().getCanonicalPath();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static String getBasePackagePath() {
		basePackagePath = getWebRootPath()+ File.separator + "WEB-INF" + File.separator + "classes" + File.separator + 
							Config.getBasePackagePath().replace(".", File.separator);
		return basePackagePath;
	}
	
	public static String getLibPath() {
		libPath = getWebRootPath()+ File.separator + "WEB-INF" + File.separator + "lib";
		return libPath;
	}

	
}
